﻿using Bank.Account;
using Bank.Operations;
using Bank.Reports;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Bank
{
    public class AccountCollection
    {
        public AccountCollection()
        {
            accountList = new List<IAccount>();
        }


        private List<IAccount> accountList;

        public List<IAccount> AccountList { get { return accountList; } }

        public IAccount GetAccountByID(String accountNumber, Int32 clientID)
        {
            IAccount account = accountList.FirstOrDefault(a => a.Number == accountNumber && a.ClientId == clientID);
            return account;
        }

        public List<IAccount> GetAccountsByIDs(List<String> accountNumber, Int32 clientID)
        {
            List<IAccount> account = accountList.Where(a => accountNumber.Contains(a.Number) && a.ClientId == clientID).ToList();
            return account;
        }

        private Int32 GetNewAccountId()
        {
            if (accountList.Count == 0)
                return 0;
            else
            {
                int newId = accountList.Max(a => a.Id);
                newId++;
                return newId;
            }
        }

        public IAccount CreateCurrentAccount(Int32 clientId)
        {
            CurrentAccount account = new CurrentAccount(clientId, GetNewAccountId());
            account.InterestCalculator = new RangeInterestCalculator();
            account.Operationlist.Add(typeof(InPayment).Name);
            account.Operationlist.Add(typeof(OutPayment).Name);
            AccountDecorator dec = new AccountDecorator(account);
            accountList.Add(dec);
            return dec;

        }
        public IAccount CreateCurrentAccount(Int32 clientId, Decimal ballance)
        {
            CurrentAccount account = new CurrentAccount(clientId, GetNewAccountId(), ballance);
            account.InterestCalculator = new RangeInterestCalculator();
            account.Operationlist.Add(typeof(InPayment).Name);
            account.Operationlist.Add(typeof(OutPayment).Name);
            AccountDecorator dec = new AccountDecorator(account);
            accountList.Add(dec);
            return dec;
        }

        public IAccount CreateCurrentAccount(Int32 clientId, Money ballance)
        {
            CurrentAccount account = new CurrentAccount(clientId, GetNewAccountId(), ballance);
            account.InterestCalculator = new RangeInterestCalculator();
            account.Operationlist.Add(typeof(InPayment).Name);
            account.Operationlist.Add(typeof(OutPayment).Name);
            AccountDecorator dec = new AccountDecorator(account);
            accountList.Add(dec);
            return dec;
        }

        public IAccount CreateDepositAccount(Int32 clientId)
        {
            DepositAccount account = new DepositAccount(clientId, GetNewAccountId());

            account.InterestCalculator = new SimpleInterestCalculator();
            account.Operationlist.Add(typeof(InPayment).Name);
            account.Operationlist.Add(typeof(OutPayment).Name);
            AccountDecorator dec = new AccountDecorator(account);
            accountList.Add(dec);
            return dec;

        }


        public IAccount CreateDepositAccount(Int32 clientId, Decimal ballance)
        {
            DepositAccount account = new DepositAccount(clientId, GetNewAccountId(), ballance);
            account.InterestCalculator = new SimpleInterestCalculator();
            account.Operationlist.Add(typeof(InPayment).Name);
            account.Operationlist.Add(typeof(OutPayment).Name);
            AccountDecorator dec = new AccountDecorator(account);
            accountList.Add(dec);
            return dec;
        }
        public IAccount CreateDepositAccount(Int32 clientId, Money ballance)
        {
            DepositAccount account = new DepositAccount(clientId, GetNewAccountId(), ballance);
            account.InterestCalculator = new SimpleInterestCalculator();
            account.Operationlist.Add(typeof(InPayment).Name);
            account.Operationlist.Add(typeof(OutPayment).Name);
            AccountDecorator dec = new AccountDecorator(account);
            accountList.Add(dec);
            return dec;
        }

        public IAccount CreateForeignCurrencyAccount(Int32 clientId, Currency cur)
        {
            ForeignCurrencyAccount account = new ForeignCurrencyAccount(clientId, GetNewAccountId(), cur);
            account.InterestCalculator = new SimpleInterestCalculator();
            account.Operationlist.Add(typeof(InPayment).Name);
            account.Operationlist.Add(typeof(OutPayment).Name);
            AccountDecorator dec = new AccountDecorator(account);
            accountList.Add(dec);
            return dec;

        }
        public IAccount CreateForeignCurrencyAccount(Int32 clientId, Decimal ballance, Currency cur)
        {
            ForeignCurrencyAccount account = new ForeignCurrencyAccount(clientId, GetNewAccountId(), cur, ballance);
            account.InterestCalculator = new SimpleInterestCalculator();
            account.Operationlist.Add(typeof(InPayment).Name);
            account.Operationlist.Add(typeof(OutPayment).Name);
            AccountDecorator dec = new AccountDecorator(account);
            accountList.Add(dec);
            return dec;
        }

        public IAccount CreateForeignCurrencyAccount(Int32 clientId, Money ballance, Currency cur)
        {
            ForeignCurrencyAccount account = new ForeignCurrencyAccount(clientId, GetNewAccountId(), cur, ballance);
            account.InterestCalculator = new SimpleInterestCalculator();
            account.Operationlist.Add(typeof(InPayment).Name);
            account.Operationlist.Add(typeof(OutPayment).Name);
            AccountDecorator dec = new AccountDecorator(account);
            accountList.Add(dec);
            return dec;
        }

        public IAccount CreateSavingsAccount(Int32 clientId)
        {
            SavingsAccount account = new SavingsAccount(clientId, GetNewAccountId());
            account.InterestCalculator = new RangeInterestCalculator();
            account.Operationlist.Add(typeof(InPayment).Name);
            account.Operationlist.Add(typeof(OutPayment).Name);
            AccountDecorator dec = new AccountDecorator(account);
            accountList.Add(dec);
            return dec;

        }
        public IAccount CreateSavingsAccount(Int32 clientId, Decimal ballance)
        {
            SavingsAccount account = new SavingsAccount(clientId, GetNewAccountId(), ballance);
            account.InterestCalculator = new RangeInterestCalculator();
            account.Operationlist.Add(typeof(InPayment).Name);
            account.Operationlist.Add(typeof(OutPayment).Name);
            AccountDecorator dec = new AccountDecorator(account);
            accountList.Add(dec);
            return dec;
        }

        public IAccount CreateSavingsAccount(Int32 clientId, Money ballance)
        {
            SavingsAccount account = new SavingsAccount(clientId, GetNewAccountId(), ballance);
            account.InterestCalculator = new RangeInterestCalculator();
            account.Operationlist.Add(typeof(InPayment).Name);
            account.Operationlist.Add(typeof(OutPayment).Name);
            AccountDecorator dec = new AccountDecorator(account);
            accountList.Add(dec);
            return dec;
        }

        public IAccount CreateSecondaryAccount(Int32 clientId)
        {
            SecondaryAccount account = new SecondaryAccount(clientId, GetNewAccountId());
            account.InterestCalculator = new SimpleInterestCalculator();
            account.Operationlist.Add(typeof(InPayment).Name);
            account.Operationlist.Add(typeof(OutPayment).Name);
            AccountDecorator dec = new AccountDecorator(account);
            accountList.Add(dec);
            return dec;

        }



        public IAccount CreateSecondaryAccount(Int32 clientId, Decimal ballance)
        {
            SecondaryAccount account = new SecondaryAccount(clientId, GetNewAccountId(), ballance);
            account.InterestCalculator = new SimpleInterestCalculator();
            account.Operationlist.Add(typeof(InPayment).Name);
            account.Operationlist.Add(typeof(OutPayment).Name);
            AccountDecorator dec = new AccountDecorator(account);
            accountList.Add(dec);
            return dec;
        }

        public IAccount CreateSecondaryAccount(Int32 clientId, Money ballance)
        {
            SecondaryAccount account = new SecondaryAccount(clientId, GetNewAccountId(), ballance);
            account.InterestCalculator = new SimpleInterestCalculator();
            account.Operationlist.Add(typeof(InPayment).Name);
            account.Operationlist.Add(typeof(OutPayment).Name);
            AccountDecorator dec = new AccountDecorator(account);
            accountList.Add(dec);
            return dec;
        }
    }
}
